<template>
  <div class="container-pt">
    <van-nav-bar
      left-arrow
      @click-left="$router.back()"
      fixed
      title="我的收藏"
    />

    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <article-list
        :disable-swiper="false"
        v-for="item in userCollect"
        :key="item.id"
        :item="item"
      >
        <van-button square type="warning" text="取消" @click="del(item.id)" />
      </article-list>
    </van-list>
  </div>
</template>

<script>
import articleList from '@/components/article-list.vue'
import { articleSc } from '@/api/article'
import request from '@/utils/request'
import { Toast } from 'vant'
export default {
  name: 'scPage',
  components: { articleList },
  data () {
    return {
      active: 0,
      loading: false,
      finished: false,
      userCollect: [],
      type: '1',
      page: '1',
      limit: '10'
    }
  },
  async created () {
  },
  methods: {
    async onLoad () {
      const res = await articleSc({
        type: this.type,
        page: this.page,
        limit: this.limit
      })
      this.userCollect.push(...res.data.list.data)
      this.loading = false
      this.page++
      if (this.page > res.data.list.totalPages) {
        this.finished = true
      }
    },
    async del (index) {
      this.userCollect = this.userCollect.filter(item => item.id !== index)
      await request.get('/user/userDataHandle', { params: { type: '1', article_id: index, action: 'del' } })
      Toast.success('取消点赞成功')
    }
  }
}
</script>

<style scoped>
img {
  width: 100px;
  height: 100px;
}
</style>
